//
//  CollectItemViewController.m
//  Mahjong
//
//  Created by KING on 16/9/1.
//  Copyright © 2016年 swift. All rights reserved.
//

#import "CollectItemViewController.h"
#import "CollectItemTableViewCell.h"
#import "Header.h"
#import "MineCollectModel.h"
@interface CollectItemViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) NSMutableArray *dateArray;

@end

@implementation CollectItemViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.view addSubview:self.myTableView];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.myTableView registerNib:[UINib nibWithNibName:@"CollectItemTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    self.dateArray = [NSMutableArray array];
    [self create];
}
-(void)create{
    [AppTools createAFN:[NSString stringWithFormat:@"http://api03.m0571.com/WebJson.aspx?book=GetCollection&page=1&userid=%@",USERID] success:^(id result) {
        NSLog(@"%@",result);
        
        for (NSDictionary *dic in [result[0] objectForKey:@"date"]) {
            MineCollectModel *model = [[MineCollectModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.dateArray addObject:model];
        }
        
        [self.myTableView reloadData];
        
    } error:^(NSError *error) {
        
        
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dateArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CollectItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    MineCollectModel *model = self.dateArray[indexPath.row];
    cell.title.text = model.GiftName;
    cell.num.text = model.salecount;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
